﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Storage;
using Windows.UI.Xaml.Media.Imaging;

namespace Praktyka.Models
{
    public class PictureManager
    {
        private int _current;
        public List<BitmapImage> _images = new List<BitmapImage>(100);
        public static string ImagePath = "dataImages";


        public BitmapImage Next()
        {
            BitmapImage image = null;
            if(HasNext())
            {
                image = _images[++_current];

            }
            return image;
        }
        public BitmapImage Previous()
        {
            BitmapImage image = null;
            if(HasPrevious())
            {
                image = _images[--_current];

            }
            return image;
        }
        public BitmapImage Current()
        {
            return _images[_current];
        }

        public bool HasPrevious()
        {
            if(_images.Count == 0) return false;
            return _current - 1 >= 0;
        }

        public bool HasNext()
        {
            return _current + 1 < _images.Count;
        }


        public async Task<List<string>> GetImages()
        {
            var files = new List<string>(5);
            StorageFolder picturesFolder = await KnownFolders.PicturesLibrary.GetFolderAsync("dataImage");
            IReadOnlyList<IStorageItem> itemsList = await picturesFolder.GetItemsAsync();
            foreach(var item in itemsList)
            {
                if(item is StorageFile)
                    files.Add(item.Name);
            }
            return files;
        }
    }
}
